﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using DAL;

namespace Prototype1.__AdminCompany
{
    public partial class WF_ExpenseChainViewer : System.Web.UI.Page
    {
        

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                String id = Request.QueryString["expenseid"];
                Guid x = default(Guid);
                if (id != null)
                {
                    x = new Guid(id);
                    ViewExpenseControl.EXPENSEID = x;
                }

                DropDownChainList.Items.Add(new ListItem("----------",""));

                using (DataAccessDataContext dc = new DataAccessDataContext())
                {
                    var query = from exp in dc.Chains
                                orderby exp.nome
                                select exp;

                    foreach(Chain c in query)
                        DropDownChainList.Items.Add(new ListItem(c.nome, c.id.ToString()));

                    if(x.CompareTo(default(Guid)) != 0)
                        DropDownChainList.Items.FindByValue(x.ToString()).Selected = true;
                }
            }            
        }

        protected void LoadChain(object sender, EventArgs e)
        {
            if (DropDownChainList.SelectedIndex > 0)
                this.ViewExpenseControl.EXPENSEID = new Guid(DropDownChainList.SelectedValue);
            else
                this.ViewExpenseControl.EXPENSEID = default(Guid);
            
        }

    }

        
}
